package org.infodavid.common.model.impl;

import org.infodavid.common.model.components.IGeoLocation;
import org.infodavid.common.model.components.ILocation;
import org.infodavid.common.model.impl.AbstractBasicDataObjectImpl;

/**
 * The Class LocationImpl.
 */
public class LocationImpl extends AbstractBasicDataObjectImpl implements ILocation {

	/** serialVersionUID. */
	private static final long serialVersionUID = 1549072855151143124L;

	/** The address. */
	private String address;

	/** The city. */
	private String city;

	/** The comment. */
	private String comment;

	/** The country. */
	private String country;

	/** The geo location. */
	private IGeoLocation geoLocation;

	/** The name. */
	private String name;

	/** The state. */
	private String state;

	/** The type. */
	private ELocationType type;

	/** The zip code. */
	private String zipCode;

	/**
	 * The Constructor.
	 * @throws Exception the exception
	 */
	protected LocationImpl() throws Exception {
		super();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.ILocation#getAddress()
	 */
	public String getAddress() {
		return address;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.ILocation#getCity()
	 */
	public String getCity() {
		return city;
	}

	/*
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.ICommented#getComment()
	 */
	public String getComment() {
		return comment;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocation#getCountry()
	 */
	public String getCountry() {
		return country;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocalizable#getGeoLocation()
	 */
	public IGeoLocation getGeoLocation() {
		return geoLocation;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.INamed#getName()
	 */
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocation#getState()
	 */
	public String getState() {
		return state;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.ILocation#getType()
	 */
	public ELocationType getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocation#getZipCode()
	 */
	public String getZipCode() {
		return zipCode;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.impl.model.DataObjectImpl#init()
	 */
	@Override
	public void init() throws Exception {
		super.init();

		address = null;
		name = null;
		city = null;
		state = null;
		country = null;
		zipCode = null;
		geoLocation = null;
		type = null;
		comment = null;
		geoLocation = null;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.ILocation#setAddress(java.lang.String)
	 */
	public void setAddress(final String value) {
		if (!equals(address, value)) {
			address = value;
			markModified(ADDRESS);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocation#setCity(java.lang.String)
	 */
	public void setCity(final String value) {
		if (!equals(city, value)) {
			city = value;
			markModified(CITY);
		}
	}

	/*
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.ICommented#setComment(java.lang.String)
	 */
	public void setComment(final String value) {
		if (!equals(comment, value)) {
			comment = value;
			markModified(COMMENT);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocation#setCountry(java.lang.String)
	 */
	public void setCountry(final String value) {
		if (!equals(country, value)) {
			country = value;
			markModified(COUNTRY);
		}
	}

	/**
	 * Sets the location.
	 * @param value the location
	 */
	public void setGeoLocation(final IGeoLocation value) {
		if (!equals(geoLocation, value)) {
			geoLocation = value;
			markModified(GEO_LOCATION);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.INamed#setName(java.lang.String)
	 */
	public void setName(final String value) {
		if (!equals(name, value)) {
			name = value;
			markModified(NAME);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocation#setState(java.lang.String)
	 */
	public void setState(final String value) {
		if (!equals(state, value)) {
			state = value;
			markModified(STATE);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.ILocation#setType(org.infodavid.common.
	 * model.entities.ILocation.ELocationType)
	 */
	public void setType(final ELocationType value) {
		if (!equals(type, value)) {
			type = value;
			markModified(TYPE);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.ILocation#setZipCode(java.lang.String)
	 */
	public void setZipCode(final String value) {
		if (!equals(zipCode, value)) {
			zipCode = value;
			markModified(ZIP_CODE);
		}
	}

	/*
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.impl.model.DataObjectImpl#toString(java.lang.StringBuffer)
	 */
	@Override
	protected StringBuffer toString(final StringBuffer builder) {
		super.toString(builder);

		builder.append(" [address=");
		builder.append(address);
		builder.append(", city=");
		builder.append(city);
		builder.append(", geoLocation=");
		builder.append(geoLocation);
		builder.append(", name=");
		builder.append(name);
		builder.append(", country=");
		builder.append(country);
		builder.append(", state=");
		builder.append(state);
		builder.append(", zipCode=");
		builder.append(zipCode);
		builder.append(", type=");
		builder.append(type);
		builder.append(", comment=");
		builder.append(comment);
		builder.append("]");

		return builder;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + (getAddress() == null ? 0 : getAddress().hashCode());
		result = prime * result + (getCity() == null ? 0 : getCity().hashCode());
		result = prime * result + (getCountry() == null ? 0 : getCountry().hashCode());
		result = prime * result + (getState() == null ? 0 : getState().hashCode());

		return prime * result + (getZipCode() == null ? 0 : getZipCode().hashCode());
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}

		if (obj == null) {
			return false;
		}

		if (!(obj instanceof ILocation)) {
			return false;
		}

		final ILocation other = (ILocation)obj;

		if (getAddress() == null) {
			if (other.getAddress() != null) {
				return false;
			}
		}
		else if (!getAddress().equals(other.getAddress())) {
			return false;
		}

		if (getCity() == null) {
			if (other.getCity() != null) {
				return false;
			}
		}
		else if (!getCity().equals(other.getCity())) {
			return false;
		}

		if (getCountry() == null) {
			if (other.getCountry() != null) {
				return false;
			}
		}
		else if (!getCountry().equals(other.getCountry())) {
			return false;
		}

		if (getState() == null) {
			if (other.getState() != null) {
				return false;
			}
		}
		else if (!getState().equals(other.getState())) {
			return false;
		}

		if (getZipCode() == null) {
			if (other.getZipCode() != null) {
				return false;
			}
		}
		else if (!getZipCode().equals(other.getZipCode())) {
			return false;
		}

		return true;
	}
}
